/*************************************************************************
Crytek Source File.
Copyright (C), Crytek Studios, 2001-2004.
-------------------------------------------------------------------------
$Id: Win32Utils.cpp,v 1.1 2008/11/26 14:26:18 PauloZaffari Exp wwwrun $
$DateTime$
Description:  This file should contain a set of functions which wrap
WIN32 functions in a more convenient fashion.
-------------------------------------------------------------------------
History:
- 16:11:2008   14:26: Created by Paulo Zaffari
*************************************************************************/

#include "stdafx.h"
#include "Win32Utils.h"

//////////////////////////////////////////////////////////////////////////
string NWin32Utils::GetWindowErrorMassage(DWORD nWindowErrorCode)
{
	char szBuffer[65535]="";
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,nWindowErrorCode,0,szBuffer,65534,NULL);
	return (string)szBuffer;
}
//////////////////////////////////////////////////////////////////////////
string NWin32Utils::GetCurrentWindowErrorMassage()
{
	char szBuffer[65535]="";
	FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM,NULL,GetLastError(),0,szBuffer,65534,NULL);
	return (string)szBuffer;
}
//////////////////////////////////////////////////////////////////////////
bool NWin32Utils::IsWindows7()
{
	OSVERSIONINFO osvi;
	ZeroMemory(&osvi, sizeof(OSVERSIONINFO));
	osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
	bool bVersionGot = GetVersionEx((OSVERSIONINFO*)&osvi);
	//alternatively available under
	//HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion

	if(!bVersionGot)
		return false;

	return osvi.dwMajorVersion >= 6 && osvi.dwMinorVersion >= 1;	
}
//////////////////////////////////////////////////////////////////////////
DWORD NWin32Utils::GetNtfsDisabledLastAccessUpdate()
{
	long		lRes		= 0;

	DWORD		dwKeyValue	= 0;	//1 if NtfsDisableLastAccessUpdate is set. We need it to be 0.
	DWORD		dwKeyType	= 0;
	DWORD		dwKeySize	= sizeof(dwKeyValue);

	const char* szKeyName	= "SYSTEM\\CurrentControlSet\\Control\\FileSystem";
	const char* szValName	= "NtfsDisableLastAccessUpdate";
	HKEY		hKey;

	lRes = RegOpenKey(HKEY_LOCAL_MACHINE, szKeyName, &hKey);
	if(lRes == ERROR_SUCCESS)
	{
		lRes = RegQueryValueEx(hKey,
			szValName,
			NULL,
			&dwKeyType,
			(BYTE*)&dwKeyValue,
			&dwKeySize);

		if(lRes != ERROR_SUCCESS)
		{
			CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, "could not retrieve value for key %s", szValName);
		}		
		RegCloseKey(hKey);
	}
	else
	{
		CryWarning(VALIDATOR_MODULE_EDITOR, VALIDATOR_ERROR, "could not retrieve key %s\\%s", "HKEY_LOCAL_MACHINE", szKeyName);
	}
	return dwKeyValue;
}
//////////////////////////////////////////////////////////////////////////
